
/*******************************************************************************
 * The code below this comment is integral part of the project "Jelliphy".
 * 
 * "Jelliphy" is a project created by: 
 * Dispage - Patrizio Gelosi
 * Via A. De Gasperi 91 
 * P. Potenza Picena (MC) - Italy
 * 
 * (Hereby referred to as "DISPAGE")
 * 
 * Copyright (c) 2011 DISPAGE.
 * 
 * @Released on: 02-06-2011
 * @Version: 1.0.00
 * @Build: 1109
 * @Site: http://www.dispage.com
 * @Contacts: http://www.dispage.com/contacts
 * 
 * The contents of this file are released under the GNU General Public License
 * version 3 as published by the Free Software Foundation that can be found at
 * the address "http://opensource.org/licenses/gpl-3.0.html". If the license
 * cannot be found, write to the Free Software Foundation, Inc., 51 Franklin
 * Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * You may not use the present file except in compliance with the License.
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * Dispage" logo. If the display of the logo is not reasonably feasible for
 * technical reasons, the Appropriate Legal Notices must display the words
 * "Powered by Dispage".
 * 
 ******************************************************************************/

var MGDefs = new function () {

	var that = this,

		posProps = ['auto', '0px', '1px', '2px', '3px', '4px', '6px', '8px', '10px', '15px', '20px'],
		dimProps = ['0px', '1px', '2px', '3px', '4px', '6px', '8px', '10px', '15px', '20px'],
		widthProps = ['0px', '1px', '2px', '3px', '4px', '5px', '6px'],
		bsProps = ['none', 'solid', 'hidden', 'dotted', 'dashed', 'double', 'groove', 'ridge', 'inset', 'outset'],
		colors = ['black', 'silver', 'maroon', 'red', 'navy', 'blue', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'teal', 'aqua', 'gray', 'white', 'transparent'],
		tableAttrs = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20'],
		shadows = ['2px 2px 1px', '-2px 2px 1px', '-2px -2px 1px', '2px -2px 1px'];


	that.colorHex = {
		black:					[0,0,0],
		silver:					[192,192,192],
		maroon:					[128,0,0],
		red:					[255,0,0],
		navy:					[0,0,128],
		blue:					[0,0,255],
		purple:					[128,0,128],
		fuchsia:				[255,0,255],
		green:					[0,128,0],
		lime:					[0,255,0],
		olive:					[128,128,0],
		yellow:					[255,255,0],
		teal:					[0,128,128],
		aqua:					[0,255,255],
		gray:					[128,128,128],
		white:					[255,255,255]
	};

	that.properties = {

		text : [
			'font',
			'font-style',
			'font-variant',
			'font-weight',
			'font-size',
			'font-family',
			'color',
			'text-transform',
			'text-decoration',
			'text-shadow',
			'letter-spacing',
			'word-spacing',
			'line-height',
			'text-align',
			'text-indent',
			'vertical-align',
			'direction'
		],
		bkground : [
			'background',
			'background-color',
			'background-image',
			'background-repeat',
			'background-attachment',
			'background-position',
			'opacity'
		],
		boxmodel : [
			'width',
			'height',
			'top',
			'right',
			'bottom',
			'left',
			'margin',
			'margin-top',
			'margin-right',
			'margin-bottom',
			'margin-left',
			'padding',
			'padding-top',
			'padding-right',
			'padding-bottom',
			'padding-left',
			'border',
			'border-width',
			'border-top-width',
			'border-right-width',
			'border-bottom-width',
			'border-left-width',
			'border-style',
			'border-top-style',
			'border-right-style',
			'border-bottom-style',
			'border-left-style',
			'border-color',
			'border-top-color',
			'border-right-color',
			'border-bottom-color',
			'border-left-color',
			'border-radius',
			'border-top-left-radius',
			'border-top-right-radius',
			'border-bottom-right-radius',
			'border-bottom-left-radius',
			'box-shadow'
		],
		layout : [
			'position',
			'display',
			'visibility',
			'z-index',
			'overflow-x',
			'overflow-y',
			'white-space',
			'clip',
			'float',
			'clear'
		],
		typespec : {
			list : [
				'list-style-image',
				'list-style-position',
				'list-style-type',
				'marker-offset'
			],
			table : [
				'table-layout',
				'border-collapse',
				'border-spacing',
				'empty-cells'
			]
		},
		other : [
			'cursor'
		]
	};

	that.autoProps = {
		'font' : [],
		'font-style' : ['normal', 'italic', 'oblique'],
		'font-variant' : ['normal', 'small-caps'],
		'font-weight' : ['normal', 'bold', 'bolder', 'lighter', '500', '900'],
		'font-size' : ['6px', '7px', '8px', '9px', '10px', '11px', '12px', '13px', '14px', '15px', '16px', '18px', '20px', '24px', '32px', '48px'],
		'font-family' : ['Arial', 'Arial Black', 'Bookman Old Style', 'Comic Sans MS', 'Courier New', 'cursive', 'fantasy', 'Georgia', 'Garamond', 'Helvetica', 'Impact', 'Lucida Grande', 'monospace', 'sans-serif', 'serif', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana'],
		'color' : colors,
		'text-transform' : ['none', 'capitalize', 'uppercase', 'lowercase'],
		'text-decoration' : ['none', 'underline', 'overline', 'line-through', 'blink'],
		'text-shadow' : shadows,
		'letter-spacing' : ['normal', '1px', '2px', '3px', '4px', '6px', '8px', '10px'],
		'word-spacing' : ['normal', '0.6em', '0.8em', '1em', '1.5em', '2em', '4em'],
		'line-height' : ['normal', '0.8em', '1em', '1.5em', '2em'],
		'text-align' : ['left', 'right', 'center', 'justify'],
		'text-indent' : ['0px', '4px', '8px', '12px', '16px', '20px', '24px', '28px', '32px', '36px'],
		'vertical-align' : ['baseline', 'sub', 'super', 'top', 'text-top', 'middle', 'bottom', 'text-bottom'],
		'direction' : ['ltr', 'rtl'],
		'background' : [],
		'background-color' : colors,
		'background-image' : ['url("...")', 'none'],
		'background-repeat' : ['repeat', 'repeat-x', 'repeat-y', 'no-repeat'],
		'background-attachment' : ['scroll', 'fixed'],
		'background-position' : ['left', 'center', 'right', 'top', 'center', 'bottom'],
		'opacity' : ['0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1.0'],
		'width' : [],
		'height' : [],
		'top' : posProps,
		'right' : posProps,
		'bottom' : posProps,
		'left' : posProps,
		'margin' : dimProps,
		'margin-top' : dimProps,
		'margin-right' : dimProps,
		'margin-bottom' : dimProps,
		'margin-left' : dimProps,
		'padding' : dimProps,
		'padding-top' : dimProps,
		'padding-right' : dimProps,
		'padding-bottom' : dimProps,
		'padding-left' : dimProps,
		'border' : [],
		'border-width' : widthProps,
		'border-top-width' : widthProps,
		'border-right-width' : widthProps,
		'border-bottom-width' : widthProps,
		'border-left-width' : widthProps,
		'border-style' : bsProps,
		'border-top-style' : bsProps,
		'border-right-style' : bsProps,
		'border-bottom-style' : bsProps,
		'border-left-style' : bsProps,
		'border-color' : colors,
		'border-top-color' : colors,
		'border-right-color' : colors,
		'border-bottom-color' : colors,
		'border-left-color' : colors,
		'border-radius' : dimProps,
		'border-top-left-radius' : dimProps,
		'border-top-right-radius' : dimProps,
		'border-bottom-right-radius' : dimProps,
		'border-bottom-left-radius' : dimProps,
		'box-shadow' : shadows,
		'position' : ['static', 'relative', 'absolute', 'fixed'],
		'display' : ['inline', 'block', 'list-item', 'run-in', 'inline-block', 'table', 'inline-table', 'table-row-group', 'table-header-group', 'table-footer-group', 'table-row', 'table-column-group', 'table-column', 'table-cell', 'table-caption', 'none'],
		'visibility' : ['visible', 'hidden', 'collapse'],
		'z-index' : ['auto'],
		'overflow-x' : ['visible', 'hidden', 'scroll', 'auto'],
		'overflow-y' : ['visible', 'hidden', 'scroll', 'auto'],
		'white-space' : ['normal', 'pre', 'nowrap', 'pre-wrap', 'pre-line'],
		'clip' : ['rect(<top>, <right>, <bottom>, <left>)', 'auto'],
		'float' : ['left', 'right', 'none'],
		'clear' : ['none', 'left', 'right', 'both'],
		'cursor' : ['auto', 'crosshair', 'default', 'pointer', 'move', 'e-resize', 'ne-resize', 'nw-resize', 'n-resize', 'se-resize', 'sw-resize', 's-resize', 'w-resize', 'text', 'wait', 'help', 'progress'],
		'list-style-image' : ['none'],
		'list-style-position' : ['inside', 'outside'],
		'list-style-type' : ['disc', 'circle', 'square', 'decimal', 'decimal-leading-zero', 'lower-roman', 'upper-roman', 'lower-greek', 'lower-latin', 'upper-latin', 'armenian', 'georgian', 'lower-alpha', 'upper-alpha', 'none'],
		'marker-offset' : [],
		'table-layout' : ['auto', 'fixed'],
		'border-collapse' : ['collapse', 'separate'],
		'border-spacing' : dimProps,
		'empty-cells' : ['show', 'hide']
	};

	that.autoAttrs = {
		'align' : ['left', 'center', 'right', 'justify', 'char'],
		'valign' : ['top', 'middle', 'center', 'bottom', 'baseline'],
		'clear' : ['left', 'right', 'all', 'both'],
		'frame' : ['void', 'above', 'below', 'hsides', 'lhs', 'rhs', 'vsides', 'box', 'border'],
		'rules' : ['none', 'groups', 'rows', 'cols', 'all'],
		'face' : ['Arial', 'Comic Sans MS', 'Courier New', 'cursive', 'fantasy', 'Georgia', 'Helvetica', 'Lucida Grande', 'monospace', 'sans-serif', 'serif', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana'],
		'method' : ['get', 'post'],
		'enctype' : ['multipart/form-data', 'application/x-www-form-urlencoded', 'text/plain'],
		'type' : ['text', 'checkbox', 'radio', 'password', 'hidden', 'submit', 'reset', 'button', 'file', 'image'],
		'withheader' : ['true', 'false'],
		'rows' : tableAttrs,
		'columns' : tableAttrs
	};

	that.shProps = {
		'font' : ['font-style' , 'font-variant', 'font-weight', 'font-size', 'font-family'],
		'background' : ['background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position'],
		'margin' : ['margin-top', 'margin-right', 'margin-bottom' , 'margin-left'],
		'padding' : ['padding-top', 'padding-right', 'padding-bottom' , 'padding-left'],
		'border-width' : ['border-top-width', 'border-right-width', 'border-bottom-width' , 'border-left-width'],
		'border-style' : ['border-top-style', 'border-right-style', 'border-bottom-style' , 'border-left-style'],
		'border-color' : ['border-top-color', 'border-right-color', 'border-bottom-color' , 'border-left-color'],
		'border' : ['border-width', 'border-style', 'border-color'],
		'border-radius' : ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius']
	};

	that.shPropsInv = {};

	that.cbProps = {
		'box-shadow' : 1, '-moz-box-shadow' : 1, '-webkit-box-shadow' : 1, 
		'border-radius' : 1, '-moz-border-radius' : 1, '-webkit-border-radius' : 1, 
		'border-top-left-radius' : 1, '-moz-border-radius-topleft' : 1, '-webkit-border-top-left-radius' : 1, 
		'border-top-right-radius' : 1, '-moz-border-radius-topright' : 1, '-webkit-border-top-right-radius' : 1, 
		'border-bottom-right-radius' : 1, '-moz-border-radius-bottomright' : 1, '-webkit-border-bottom-right-radius' : 1, 
		'border-bottom-left-radius' : 1, '-moz-border-radius-bottomleft' : 1, '-webkit-border-bottom-left-radius' : 1
	};
	that.cbPropsArr = [];
	that.cbSelected = '';

	that.crossPrefix = ['-moz-', '-webkit-', ''];

	that.dimensionedProps = {'margin' : 1, 'padding' : 1, 'border-width' : 2, 'border-style' : 2, 'border-color' : 2, 'background-position' : 1, 'border-radius' : 1};

	
	that.init = function () {

		var p, q, i,
			radiusRx = /-moz-border-([^\-]+)-([^\-]+)-radius$/,
			radiusRep = '-moz-border-radius-$1$2';

		that.cbPropsArr = JlQ.objKeys(that.cbProps);

		if ((JlQ.browser.mozilla3 && (that.cbSelected = '-moz-')) || (JlQ.browser.safari && (that.cbSelected = '-webkit-'))) {
			JlQ.each(that.cbPropsArr, function (i, v) {
				
				if (i % 3) return true;

				var ofs = (that.cbSelected == '-moz-') ? 1 : 2,
					newV = that.cbPropsArr[i + ofs];

				that.autoProps[newV] = that.autoProps[v];
				delete that.autoProps[v];
				that.properties.boxmodel[JlQ.inArray(v, that.properties.boxmodel)] = newV;
				if (v == 'border-radius') {
					that.dimensionedProps[newV] = 1;
					that.shProps[newV] = JlQ.map(that.shProps[v], function (s) {return (that.cbSelected + s).replace(radiusRx, radiusRep)}); 
				}
			});
		}
		for (p in that.shProps) {
			if (p == 'border') continue;
			for (i = 0; q = that.shProps[p][i]; i++) {
				that.shPropsInv[q] = p;
			}
		}
	}

};

